package cn.xsshome.neuroph;

import java.io.File;
import java.io.IOException;
import java.util.HashMap;

import org.neuroph.core.NeuralNetwork;
import org.neuroph.core.exceptions.VectorSizeMismatchException;
import org.neuroph.imgrec.ImageRecognitionPlugin;

/**
 * 图像识别模型测试示例代码
 * @author 小帅丶
 *
 */
public class ImageRecognitionSample {
	static NeuralNetwork<?> nnet = null;
	static{
		 // 加载用Neuroph Studio训练保存的神经网络文件 
		nnet = NeuralNetwork.createFromFile("animals_net.nnet");
	}
	public static void main(String[] args) {
		long startTime = System.currentTimeMillis();
        // 从神经网络中获取图像是被插件类
        ImageRecognitionPlugin imageRecognition = (ImageRecognitionPlugin)nnet.getPlugin(ImageRecognitionPlugin.class);
        try {
              // 给定具体要测试的图片路径
              HashMap<String, Double> output = imageRecognition.recognizeImage(new File("G:/testimg/animals/pandatest.jpg")); // specify some existing image file here
              long endTime = System.currentTimeMillis();
              System.out.println(output.toString() + "\n" + "耗时:" + (endTime-startTime)+"ms");
        } catch(IOException ioe) {
            System.out.println("Error: could not read file!");
        } catch (VectorSizeMismatchException vsme) {
            System.out.println("Error: Image dimensions dont !");
        }
  }
}
